package com.lgj.demo0812.TestDemo;

import java.util.Scanner;

/**
 * @author lizy51
 * @date 2022-09-16 17:19
 */
public class Recursion {
    public static void main(String[] args) {
        System.out.println("请输入正整数");
        int number = demo();
        int flag = number;
//        int mark = 0;
        if (number >= 0) {
            int figure = figure(number, flag);
            System.out.println(figure);
        } else {
            System.out.println("请输入不小于0的整数");
            demo();
        }
    }

    public static int demo() {
        Scanner sc = new Scanner(System.in);
        try {
            int i = sc.nextInt();
            return i;
        } catch (Exception e) {
            System.out.println("请输入正确的整数");
            demo();
            return -1;
        }
    }

    public static int figure(int num, int flag) {
        if (num < 2) return 1;
        num--;
        if (num > 1) {
            flag = flag * num;
            return figure(num, flag);
        }
        return flag;
    }
}
